package br.ufrj.dcc.dojo.jtrace;

import java.io.IOException;

import org.jtrace.Material;
import org.jtrace.Materials;
import org.jtrace.Scene;
import org.jtrace.Tracer;
import org.jtrace.cameras.Camera;
import org.jtrace.cameras.PinHoleCamera;
import org.jtrace.geometry.MeshObject;
import org.jtrace.geometry.Plane;
import org.jtrace.lights.Light;
import org.jtrace.primitives.ColorRGB;
import org.jtrace.primitives.Point3D;
import org.jtrace.primitives.Vector3D;
import org.jtrace.shader.Shader;
import org.jtrace.shader.Shaders;

import br.ufrj.dcc.dojo.jtrace.interceptor.ShadowInterceptor;

public class SingleMesh extends TracerComponents {
	
	private String ply;

	public SingleMesh(String ply, int hres, int vres) {
		super(hres, vres);
		this.ply = ply;
	}
	
	@Override
	protected void createScene(Scene scene) throws IOException {
		Point3D eye = new Point3D(0, 0, 30);
		Point3D lookAt = Point3D.ORIGIN;
		Vector3D up = Vector3D.UNIT_Y;
		Camera camera = new PinHoleCamera(eye, lookAt, up);
		camera.setZoomFactor(20d);
		scene.setCamera(camera);

		MeshObject mesh = new MeshObject(ply, Materials.matte(ColorRGB.YELLOW));
		mesh.insertScene(scene);
		
		Point3D pointPlane = new Point3D(0, 0, 0);
		Vector3D normalPlane = new Vector3D(0, 1, 1);
		Material material = Materials.metallic(ColorRGB.WHITE);
		Plane plane = new Plane(pointPlane, normalPlane, material);
		scene.add(plane);
		
		Point3D lightPoint = new Point3D(10, 0, 10);
		Light light = new Light(lightPoint);
		scene.add(light);
	}

	@Override
	protected void createTracer(Tracer tracer) {
		Shader ambient = Shaders.ambientShader();
		Shader diffuse = Shaders.diffuseShader();
		Shader specular = Shaders.specularShader(64);
		
		ShadowInterceptor shadow = new ShadowInterceptor();
		tracer.addInterceptors(shadow);
		
		tracer.addShaders(ambient, diffuse, specular);
	}
	
}